package com.zzp.convert;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.File;
import java.io.FileWriter;

public class PdfToTextConverter {
    public static void convert(String pdfPath, String txtPath) {
        try (PDDocument document = PDDocument.load(new File(pdfPath))) {
            PDFTextStripper stripper = new PDFTextStripper();
            String text = stripper.getText(document);

            try (FileWriter writer = new FileWriter(txtPath)) {
                writer.write(text);
            }
            System.out.println("转换成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        convert("D:\\code\\zzp\\big.pdf", "D:\\code\\zzp\\big.txt");
    }
}
